<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="Content-Script-Type" content="text/javascript" />
		<meta http-equiv="Content-Style-Type" content="text/css" />
		<title>コントロールパネル</title>
		<link rel="stylesheet" href="./assets/styles/default.css" type="text/css" />
		<script src="assets/scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
		<script src="assets/scripts/menu.js" type="text/javascript"></script>
		<script src="assets/scripts/table.js" type="text/javascript"></script>
		<link type="text/css" href="./assets/styles/ui-lightness/jquery-ui-1.7.2.custom.css" rel="stylesheet" />
		<script type="text/javascript" src="./assets/scripts/ui/ui.core.js"></script>
		<script type="text/javascript" src="./assets/scripts/ui/ui.datepicker.js"></script>
		<script type="text/javascript">
		$(function() {
			$('.message').fadeIn("slow");
			$('#btn-export').click(function(){	
				if(confirm('ダウンロードしますか？')){
					document.fn.csv.value="download";
					document.fn.submit();
				}
			});
			$('#btn-reset').click(function(){	
				location.href = document.fn.action;
			});
			
			$('#btn_search').click(function(){
				if ( chkWeek() ) {
					document.fn.csv.value="";
					document.fn.submit();
				 }
			});
			
			$('.text_date').datepicker({
				changeMonth: true,
				changeYear: true,
				dateFormat: 'yy/mm/dd'
			});
			
			$('#year4').change(function(){
				var year4 = this.value;
				var myDate = new Date();
				var nowtime =  myDate.getTime();
				$.get("mmap_week_ajax.php",{ y: year4,t : nowtime }, function(data){
					$("#matrix_cd").children().remove();
					$("#matrix_cd").append( data ); 
				});
			});
			$('#year4c').change(function(){
				var year4c = this.value;
				var myDate = new Date();
				var nowtime =  myDate.getTime();
				$.get("mmap_week_ajax.php",{ y: year4c,t : nowtime }, function(data){
					$("#matrix_cdc").children().remove();
					$("#matrix_cdc").append( data ); 
				});
			});
			$('#btn-copy').click(function(){	
				var weekid = $("#matrix_cdc").val();
				if (weekid.length == 0){
					alert("コピー週を選択してください");
					return false;
				 }
				if( !confirm('コピーしてよろしいですか？') ){
					return false;
				}
				var weekfrom = document.fn.fweek.value;
				var year4c = $("#year4c").val();
				if (weekfrom==weekid) {
					alert("同じ週のデータはコピーできません");
					return false;
				}
				var myDate = new Date();
				var nowtime =  myDate.getTime();
				var tabCnt = 0;

				$.get("ajax_ins_shops_tab_exist.php",{ w: weekid,t : nowtime }, function(data){
					//alert(data);
					tabCnt = 1 * data;
					 if ( tabCnt ==1 ) {
						if( confirm('該当週のデータは既に存在します、コピーしてもよろしいですか？') ){
							document.fn.tweek.value = weekid;
							document.fn.csv.value = 'copy';
							document.fn.submit();
						}
					}
					if  ( tabCnt == 0 ) {
						alert("該当週のテーブルは存在しない。\r\nコピー前にテーブルを作成してください");
						return false;
					}
					
					if  ( tabCnt == 100 ) {
						document.fn.tweek.value = weekid;
						document.fn.csv.value="copy";
						document.fn.submit();
						return false;
					 }
				});
				 //document.fn.submit();
			});
			$('#btn-upd-ins').click(function(){
				//document.fn.tweek.value = weekid;
				document.fn.csv.value="updins";
				document.fn.submit();
				return false;
			});
			
			$('#btn-add').click(function(){	
				 if ( chkWeek() ) {
					 location.href = "minsshopshop_form.php?w=" + $("#matrix_cd").val();
				 }
			});
			
			$('.d_upd').click(function(){
				 if ( chkWeek() ) {
					 location.href = "minsshopshop_form.php?id=" +this.id + "&w=" + $("#matrix_cd").val();
				}
			});
		});
		
		function toPage(thepage) {
			document.fn.page.value =  thepage;
			document.fn.csv.value="";
			document.fn.submit();
		}
		
		function chkWeek() {
			var weekid = $("#matrix_cd").val() ;
			if (weekid.length == 0){
				alert("週を選択してください");
				return false;
			 }
			return true;
		}
		</script>
		<link rel="stylesheet" type="text/css" href="./assets/styles/tablesorter.css" />
		<script type="text/javascript" src="./assets/scripts/tablesorter.js"></script>
	</head>
	<body id="">
{{$menu}}
{{$logout}}
		<div id="container"><div class="wrapper">
			<h2>販売店紐付けマスター管理</h2>
			<ul class="submenu clearfix">
				<li>販売店紐付け情報一覧</li>
			</ul>
			<h3>販売店紐付け情報一覧</h3>
			<form name="fn" id="fn" method="get" action="minsshopshop_index.php" >
				<input type="hidden" name="page" />
				<table class="formTable">
					<tbody><tr>
						<th>※年度.週</th>
							<td>
{{ html_options id='year4' name='year4' options=$year4 selected=$forms.year4 }} 年{{ $err.year4 }}&nbsp;&nbsp;&nbsp;
{{ html_options id='matrix_cd' name='matrix_cd' options=$week  selected=$forms.matrix_cd }}{{ $err.matrix_cd }}
							</td>
						</tr><tr>
							<th>店舗コード</th>
							<td>
								<input type="text" name="shop_cd" value="{{ $forms.shop_cd }}" class="text" />
							</td>
						</tr><tr>
							<th>店舗名</th>
							<td>
								<input type="text" name="shop_name" value="{{ $forms.shop_name }}" class="text" />
							</td>
						</tr>
						<!--  
						<tr>
							<th>販売店コード</th>
							<td>
								<input type="text" name="ins_shop_cd" value="{{ $forms.ins_shop_cd }}" class="text" />
							</td>
						</tr>
						-->
						<tr><th>販売店名</th>
							<td>
								<input type="text" name="ins_shop_name" value="{{ $forms.ins_shop_name }}" class="text" />
							</td>
						</tr><tr>
							<th>地域広告紐付</th>
							<td>
							{{ html_radios name='area_disp_ng' options=$areaflags selected=$forms.area_disp_ng separator='&nbsp;' }}
							</td>
						</tr>
						<tr>
							<th>非表示設定</th>
							<td>
{{ html_radios name='disp_ng' options=$flags selected=$forms.disp_ng separator='&nbsp;' }}
							</td>
						</tr><tr><th>重複チェック</th>
							<td>
								<label><input class="chkinput" type="checkbox" name="repeat_flg" value="1" {{if $forms.repeat_flg }}checked{{/if}}  /> 有効なGEOコードの重複チェック</label>
							</td>
						</tr><tr>
							<th>更新日</th>
							<td>
								<input type="text" name="upd_f" class="text_date" value="{{ $forms.upd_f }}" /> ～ 
								<input type="text" name="upd_t" class="text_date" value="{{ $forms.upd_t }}" />
							</td></tr>
					</tbody>
				</table>
				<p class="button" style="text-align:right">
					<button type="button" id="btn-reset"><span>クリア</span></button>
					<button type="button" id="btn_search" class="submit"><span>絞込検索</span></button>
				</p>
				<input type="hidden" name="search" value="1" />
				<input type="hidden" name="csv" />
				<input type="hidden" name="tweek" />
				<input type="hidden" name="fweek"  value = "{{$forms.matrix_cd}}"/>
			</form>
			{{if (!$isG5) }}
				<p class="button" style="text-align:left">
					<button type="button" id="btn-add"  ><span>新規追加</span></button>
				</p>
			{{/if}}
{{ if is_numeric($page.cnt) }}
{{ if $page.cnt > 0 }}
			<p class="message">{{ $page.cnt }}件の情報が見つかりました。</p>
			<p align="left">{{$pageing}}</p>
			<table id="search_result" class="sortable" >
				<thead>
					<tr>
						<th><h3>表示</h3></th>
						<th><h3>店舗コード</h3></th>
						<th><h3>店名</h3></th>
						<th><h3>地域広告<br>紐付</h3></th>
						<th><h3>販売店コード</h3></th>
						<th><h3>販売店名</h3></th>
						<th><h3>更新日時</h3></th>
						<th><h3>更新者</h3></th>
						{{if (!$isG5) }}<th><h3>操作</h3></th>{{ /if }}
					</tr>
				</thead>
				<tbody>
{{$nowindex =0}}
{{ foreach from=$data key=k item=v name="member" }}
				<tr class="{{cycle values=odd,mod name='member'}}">
	{{ if  $v.rowspan==1 }}	
		{{$nowindex = $nowindex + 1}}	
						<td rowspan={{ $v.rowspannums }} class="{{ $v.rowspanclass }} center" >
		{{ if $v.disp_ng=='1' }}
									<img src="assets/images/batu.png" > 
		{{ else }}
									&nbsp;
		{{ /if }}
						</td>
						<td rowspan={{ $v.rowspannums }} class="{{ $v.rowspanclass }}">{{ $v.shop_cd }}</td>
						<td rowspan={{ $v.rowspannums }} class="{{ $v.rowspanclass }}">{{ $v.shop_name }}</td>
	{{ /if }}
						<td>{{ $v.area_disp }}</td>
						<td>{{ $v.ins_shop_cd }}</td>
						<td>{{ $v.ins_shop_name }}</td>
	{{ if  $v.rowspan==1 }}	
						<td  rowspan={{ $v.rowspannums }}  class="center {{ $v.rowspanclass }}">{{ $v.u_time|date_format:"%Y/%m/%d %H:%M" }}</td>
						<td  rowspan={{ $v.rowspannums }}  class="{{ $v.rowspanclass }}">{{ $v.m_user_name }}</td>
	
					{{if (!$isG5) }}<td  rowspan={{ $v.rowspannums }}  class="center {{ $v.rowspanclass }}"> <a href='#' id='{{$v.shop_cd}}'  class='d_upd'> [更新]</a></td>{{ /if }}
	{{ /if }}
					</tr>
{{ /foreach }}
				</tbody>
			</table>
			{{if (!$isG5) }}
				<p align="right">{{$pageing}}</p>
				<p>結果を{{ html_options id='year4c' name='year4c' options=$year4 selected=$forms.year4c }} 年　{{ html_options id='matrix_cdc' name='matrix_cdc' options=$weekc  selected=$forms.matrix_cdc }}週へ<button type="button" id="btn-copy"  ><span>コピー</span></button> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ if $copymsg }} {{ $copymsg }}{{/if}}</p>
				<p>結果の販売店情報を更新する&nbsp;<button type="button" id="btn-upd-ins" ><span> 実行 </span></button> &nbsp;&nbsp;&nbsp;&nbsp;{{ if $updinsmsg }} {{ $updinsmsg }}{{/if}}</p>
			{{ /if }}
				<p class="button">
					<button type="button" id="btn-export"  ><span>CSVダウンロード</span></button>
				</p>

{{ else }}
<p class="message">条件にマッチする情報は見つかりませんでした。</p>
{{ /if }}
{{ else }}
	<p class="message">ここに検索結果が表示されます。</p>
{{ /if }}

		</div></div>
		{{ $footer }}
	</body>
</html>